<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 组合继承  用原型链实现原型和方法的继承，借用构造技术实现实例属性继承
        // 缺点  有两份相同的属性 影响性能
        function SuperType(name) {
            this.colors = ['red', 'blue', 'green']
            this.name = name
        }
        SuperType.prototype.sayName = function () {
            console.log(this.name)
        }
        function SubType(name, age) {
            //第二次调用 复制实例
            SuperType.call(this, name)
            this.age = age
        }
        //第一次调用
        SubType.prototype = new SuperType()
        SubType.prototype.constructor = SubType
        SubType.prototype.sayAge = function () {
            console.log(this.age)
        }
        var instance1 = new SubType('zwj', 18)
        instance1.colors.push('black')
        console.log(instance1)

        var instance2 = new SubType('zwj', 18)
        console.log(instance2)
    </script>
</body>

</html>